﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Linq;
using Styx.Common;

namespace TuanHA_Hunter
{
    public partial class THHunterForm : Form
    {
        public THHunterForm()
        {
            InitializeComponent();
        }

        private void THHunterForm_Load(object sender, EventArgs e)
        {
            if (
                File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\TuanHA-Hunter-Picture.jpg"))
            {
                pictureBox1.ImageLocation = Utilities.AssemblyDirectory +
                                            @"\Routines\TuanHAHunter\TuanHA-Hunter-Picture.jpg";
            }

            if (File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\SpecialThanks.rtf"))
            {
                richTextBox1.LoadFile(Utilities.AssemblyDirectory +
                                      @"\Routines\TuanHAHunter\SpecialThanks.rtf");
            }

            tabControl1.TabPages.Remove(tabPage4);

            AMoCLRCD.Checked = THSettings.Instance.AMoCLRCD;
            AMoCLRCBurst.Checked = THSettings.Instance.AMoCLRCBurst;
            AutoAoE.Checked = THSettings.Instance.AutoAoE;
            AutoAspect.Checked = THSettings.Instance.AutoAspect;
            AutoCallPet.Checked = THSettings.Instance.AutoCallPet;
            AutoFace.Checked = THSettings.Instance.AutoFace;
            AutoMove.Checked = THSettings.Instance.AutoMove;
            AutoRacial.Checked = THSettings.Instance.AutoRacial;
            AutoSetFocus.Checked = THSettings.Instance.AutoSetFocus;
            AutoTarget.Checked = THSettings.Instance.AutoTarget;
            AttackASAP.Checked = THSettings.Instance.AttackASAP;
            AttackASAPInStealth.Checked = THSettings.Instance.AttackASAPInStealth;
            AttackOOC.Checked = THSettings.Instance.AttackOOC;
            Backward.SelectedIndex = THSettings.Instance.Backward;
            BestialWrathCD.Checked = THSettings.Instance.BestialWrathCD;
            BestialWrathBurst.Checked = THSettings.Instance.BestialWrathBurst;
            BestialWrathLC.Checked = THSettings.Instance.BestialWrathLC;
            BullHeaded.Checked = THSettings.Instance.BullHeaded;
            BurstKey.SelectedIndex = THSettings.Instance.BurstKey;
            BurstHP.Value = THSettings.Instance.BurstHP;
            CallPetNumber.Value = THSettings.Instance.CallPetNumber;
            CallPetNumberMM.Value = THSettings.Instance.CallPetNumberMM;
            CallPetNumberSV.Value = THSettings.Instance.CallPetNumberSV;
            Camouflage.Checked = THSettings.Instance.Camouflage;
            CamouflageCombat.Checked = THSettings.Instance.CamouflageCombat;
            CamouflageCombatPercent.Value = THSettings.Instance.CamouflageCombatPercent;
            ConcussiveShot.Checked = THSettings.Instance.ConcussiveShot;
            Cower.Checked = THSettings.Instance.Cower;
            CowerPercent.Value = THSettings.Instance.CowerPercent;
            DeterrenceHP.Checked = THSettings.Instance.DeterrenceHP;
            DeterrenceHPPercent.Value = THSettings.Instance.DeterrenceHPPercent;
            DeterrenceUnit.Checked = THSettings.Instance.DeterrenceUnit;
            DeterrenceUnitNumber.Value = THSettings.Instance.DeterrenceUnitNumber;
            Disengage.Checked = THSettings.Instance.Disengage;
            DisengageUnitNumber.Value = THSettings.Instance.DisengageUnitNumber;
            ExhilarationMe.Checked = THSettings.Instance.Exhilaration;
            ExhilarationMePercent.Value = THSettings.Instance.ExhilarationMe;
            ExhilarationPet.Checked = THSettings.Instance.ExhilarationPetHP;
            ExhilarationPetPercent.Value = THSettings.Instance.ExhilarationPet;
            ExplosiveTrapDPS.Checked = THSettings.Instance.ExplosiveTrapDPS;
            ExplosiveTrapMoM.Checked = THSettings.Instance.ExplosiveTrapMoM;
            ExplosiveTrapMoMDistance.Value = THSettings.Instance.ExplosiveTrapMoMDistance;
            FeignDeath.Checked = THSettings.Instance.FeignDeath;
            FeignDeathPercent.Value = THSettings.Instance.FeignDeathPercent;
            Flare.Checked = THSettings.Instance.Flare;
            FocusFreezingTrap.SelectedIndex = THSettings.Instance.FocusFreezingTrap;
            Forward.SelectedIndex = THSettings.Instance.Forward;
            FreezingTrap.Checked = THSettings.Instance.FreezingTrap;
            FreezingTrapODM.Checked = THSettings.Instance.FreezingTrapODM;
            FreezingTrapODMDPS.Checked = THSettings.Instance.FreezingTrapODMDPS;
            FreezingTrapODMHealer.Checked = THSettings.Instance.FreezingTrapODMHealer;
            FreezingTrapMoM.Checked = THSettings.Instance.FreezingTrapMoM;
            FreezingTrapMoMDistance.Value = THSettings.Instance.FreezingTrapMoMDistance;
            PetGrowlPetAttackingMe.Checked = THSettings.Instance.PetGrowlPetAttackingMe;
            IceTrapMoM.Checked = THSettings.Instance.IceTrapMoM;
            IceTrapMoMDistance.Value = THSettings.Instance.IceTrapMoMDistance;
            IceTrapSV.Checked = THSettings.Instance.IceTrapSV;
            InterruptAll.Checked = THSettings.Instance.InterruptAll;
            InterruptTarget.Checked = THSettings.Instance.InterruptTarget;
            InterruptFocus.Checked = THSettings.Instance.InterruptFocus;
            IntimidationInterrupt.Checked = THSettings.Instance.IntimidationInterrupt;
            IntimidationInterruptMS.Value = THSettings.Instance.IntimidationInterruptMS;
            IntimidationLowHP.Checked = THSettings.Instance.IntimidationLowHP;
            IntimidationLowHPPercent.Value = THSettings.Instance.IntimidationLowHPPercent;
            IntimidationFriendLowHP.Checked = THSettings.Instance.IntimidationFriendLowHP;
            IntimidationFriendLowHPPercent.Value = THSettings.Instance.IntimidationFriendLowHPPercent;
            KillShotOffTarget.Checked = THSettings.Instance.KillShotOffTarget;
            LastStand.Checked = THSettings.Instance.LastStand;
            LastStandPercent.Value = THSettings.Instance.LastStandPercent;
            MarkASAP.Checked = THSettings.Instance.MarkASAP;
            MasterCallMe.Checked = THSettings.Instance.MasterCallMe;
            MendPet.Checked = THSettings.Instance.MendPet;
            MendPetPercent.Value = THSettings.Instance.MendPetPercent;
            Misdirection.Checked = THSettings.Instance.Misdirection;
            PauseKey.SelectedIndex = THSettings.Instance.PauseKey;
            PetAttack.Checked = THSettings.Instance.PetAttack;
            PetAttackHP.Value = THSettings.Instance.PetAttackHP;
            PetFollow.Checked = THSettings.Instance.PetFollow;
            PetFollowHP.Value = THSettings.Instance.PetFollowHP;
            PetFollowDist.Checked = THSettings.Instance.PetFollowDist;
            PetFollowDistYard.Value = THSettings.Instance.PetFollowDistYard;
            PetStunMoM.Checked = THSettings.Instance.PetStunMoM;
            PetTankAdd.Checked = THSettings.Instance.PetTankAdd;
            ProfBuff.SelectedIndex = THSettings.Instance.ProfBuff;
            ProfBuffHP.Value = THSettings.Instance.ProfBuffHP;
            ScatterShotInterrupt.Checked = THSettings.Instance.ScatterShotInterrupt;
            ScatterShotInterruptMS.Value = THSettings.Instance.ScatterShotInterruptMS;
            ScatterShotFriendLowHP.Checked = THSettings.Instance.ScatterShotFriendLowHP;
            ScatterShotFriendLowHPPercent.Value = THSettings.Instance.ScatterShotFriendLowHPPercent;
            RapidFireCD.Checked = THSettings.Instance.RapidFireCD;
            RapidFireBurst.Checked = THSettings.Instance.RapidFireBurst;
            Readiness.Checked = THSettings.Instance.Readiness;
            ReadinessAM.Checked = THSettings.Instance.ReadinessAM;
            ReadinessBW.Checked = THSettings.Instance.ReadinessBW;
            ReadinessLR.Checked = THSettings.Instance.ReadinessLR;
            ReadinessRF.Checked = THSettings.Instance.ReadinessRF;
            ReadinessScS.Checked = THSettings.Instance.ReadinessScS;
            ReadinessFT.Checked = THSettings.Instance.ReadinessFT;
            ReadinessSiS.Checked = THSettings.Instance.ReadinessSiS;
            ReadinessDe.Checked = THSettings.Instance.ReadinessDe;
            RoarofSacrifice.Checked = THSettings.Instance.RoarofSacrifice;
            RoarofSacrificePercent.Value = THSettings.Instance.RoarofSacrificePercent;
            RoarofSacrificeUnitMode.Checked = THSettings.Instance.RoarofSacrifice;
            RoarofSacrificeUnit.Value = THSettings.Instance.RoarofSacrificeUnit;
            ScareBeastKey.SelectedIndex = THSettings.Instance.ScareBeastKey;
            ScatterShotMoM.Checked = THSettings.Instance.ScatterShotMoM;
            SearchInterval.Value = THSettings.Instance.SearchInterval;
            SearchRange.Value = THSettings.Instance.SearchRange;
            SerpentStingImproved.Checked = THSettings.Instance.SerpentStingImproved;
            SilencingShotInterrupt.Checked = THSettings.Instance.SilencingShotInterrupt;
            SilencingShotInterruptMS.Value = THSettings.Instance.SilencingShotInterruptMS;
            SilencingShotLowHP.Checked = THSettings.Instance.SilencingShotLowHP;
            SilencingShotLowHPPercent.Value = THSettings.Instance.SilencingShotLowHPPercent;
            SnakeTrapMoM.Checked = THSettings.Instance.SnakeTrapMoM;
            SnakeTrapMoMDistance.Value = THSettings.Instance.SnakeTrapMoMDistance;
            SnakeTrapCasterHealer.Checked = THSettings.Instance.SnakeTrapCasterHealer;
            SpiritMend.Checked = THSettings.Instance.SpiritMend;
            SpiritMendMe.Value = THSettings.Instance.SpiritMendMe;
            SpiritMendP.Checked = THSettings.Instance.SpiritMendP;
            SpiritMendPet.Value = THSettings.Instance.SpiritMendPet;
            StampedeCD.Checked = THSettings.Instance.StampedeCD;
            StampedeBurst.Checked = THSettings.Instance.StampedeBurst;
            StrafleLeft.SelectedIndex = THSettings.Instance.StrafleLeft;
            StrafleRight.SelectedIndex = THSettings.Instance.StrafleRight;
            TargetFreezingTrap.SelectedIndex = THSettings.Instance.TargetFreezingTrap;
            TranquilizingShot.Checked = THSettings.Instance.TranquilizingShot;
            TrapSmokeBomb.Checked = THSettings.Instance.TrapSmokeBomb;
            Trinket1.SelectedIndex = THSettings.Instance.Trinket1;
            Trinket1HP.Value = THSettings.Instance.Trinket1HP;
            Trinket2.SelectedIndex = THSettings.Instance.Trinket2;
            Trinket2HP.Value = THSettings.Instance.Trinket2HP;
            TurnRight.SelectedIndex = THSettings.Instance.TurnRight;
            TurnLeft.SelectedIndex = THSettings.Instance.TurnLeft;
            UnittoStartAoE.Value = THSettings.Instance.UnittoStartAoE;
            UseFood.Checked = THSettings.Instance.UseFood;
            UseFoodHP.Value = THSettings.Instance.UseFoodHP;
            WidowVenom.Checked = THSettings.Instance.WidowVenom;
        }

        private void OK_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("TuanHA Paladin Settings have been saved", "Save");
            THSettings.Instance.Save();
            Logging.Write("----------------------------------");
            Logging.Write("TuanHA Hunter Settings have been saved");

            Logging.Write(LogLevel.Diagnostic, "Your Setting for Debug Purpose Only");
            foreach (var var in THSettings.Instance.GetSettings())
            {
                Logging.Write(LogLevel.Diagnostic, var.ToString());
            }

            Close();

            THSettings.Instance.UpdateStatus = true;
        }

        private void Apply_Click(object sender, EventArgs e)
        {
            THSettings.Instance.Save();
            Logging.Write("TuanHA Hunter Settings have been saved");
            THSettings.Instance.UpdateStatus = true;
        }

        private void Dungeon_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                Classname.GetCurrentSpec() + " Hunter " +
                "Dungeon Mode: Work best with LazyRaider/Tyrael in Dungeon.",
                //\r\n\r\nMake sure ONLY 3 Options Enabled in LazyRaider:\r\n - Run Without a Tank\r\n - Disable Plug-ins\r\n - Frame Lock",
                "Important Note",
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            Logging.Write("----------------------------------");
            Logging.Write("Dungeon Mode On");
            Logging.Write("----------------------------------");

            if (File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Dungeon.xml"))
            {
                Logging.Write("----------------------------------");
                THSettings.Instance.LoadFromXML(XElement.Load(Utilities.AssemblyDirectory +
                                                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Dungeon.xml"));
                Logging.Write("Load TuanHA Hunter Defaut Dungeon Settings from a file complete");
                Logging.Write("----------------------------------");
                THHunterForm_Load(null, null);
            }
            else
            {
                Logging.Write("----------------------------------");
                Logging.Write("File not exists: " + Utilities.AssemblyDirectory +
                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Dungeon.xml");
                Logging.Write("Load TuanHA Hunter Defaut AFK Dungeon from a file fail.");
                Logging.Write("----------------------------------");
            }
        }

        private void Raid_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                Classname.GetCurrentSpec() + " Hunter " +
                "Raid Mode: Work best with LazyRaider/Tyrael in Raid.",
                //\r\n\r\nMake sure ONLY 3 Options Enabled in LazyRaider:\r\n - Run Without a Tank\r\n - Disable Plug-ins\r\n - Frame Lock",
                "Important Note",
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            Logging.Write("----------------------------------");
            Logging.Write("Raid Mode On");
            Logging.Write("----------------------------------");

            if (File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Raid.xml"))
            {
                Logging.Write("----------------------------------");
                THSettings.Instance.LoadFromXML(XElement.Load(Utilities.AssemblyDirectory +
                                                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Raid.xml"));
                Logging.Write("Load TuanHA Hunter Defaut Raid Settings from a file complete");
                Logging.Write("----------------------------------");
                THHunterForm_Load(null, null);
            }
            else
            {
                Logging.Write("----------------------------------");
                Logging.Write("File not exists: " + Utilities.AssemblyDirectory +
                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Raid.xml");
                Logging.Write("Load TuanHA Hunter Defaut AFK Raid from a file fail.");
                Logging.Write("----------------------------------");
            }
        }

        private void PvP_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                Classname.GetCurrentSpec() + " Hunter " +
                "PvP Mode: Work best with LazyRaider/Tyrael in PvP.",
                //\r\n\r\nMake sure ONLY 3 Options Enabled in LazyRaider:\r\n - Run Without a Tank\r\n - Disable Plug-ins\r\n - Frame Lock",
                "Important Note",
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            Logging.Write("----------------------------------");
            Logging.Write("Dungeon Mode On");
            Logging.Write("----------------------------------");

            if (File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut PvP.xml"))
            {
                Logging.Write("----------------------------------");
                THSettings.Instance.LoadFromXML(XElement.Load(Utilities.AssemblyDirectory +
                                                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut PvP.xml"));
                Logging.Write("Load TuanHA Hunter Defaut PvP Settings from a file complete");
                Logging.Write("----------------------------------");
                THHunterForm_Load(null, null);
            }
            else
            {
                Logging.Write("----------------------------------");
                Logging.Write("File not exists: " + Utilities.AssemblyDirectory +
                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut PvP.xml");
                Logging.Write("Load TuanHA Hunter Defaut AFK PvP from a file fail.");
                Logging.Write("----------------------------------");
            }
        }

        private void Quest_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                Classname.GetCurrentSpec() + " Hunter " +
                "Quest Helper Mode: Work best with LazyRaider/Tyrael in solo questing.\r\n\r\nJust select your target, the bot will move to melee range and attack.",
                //\r\n\r\nMake sure ONLY 3 Options Enabled in LazyRaider:\r\n - Run Without a Tank\r\n - Disable Plug-ins\r\n - Frame Lock",
                "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Logging.Write("----------------------------------");
            Logging.Write("Quest Helper Mode On");
            Logging.Write("----------------------------------");

            if (File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Quest.xml"))
            {
                Logging.Write("----------------------------------");
                THSettings.Instance.LoadFromXML(XElement.Load(Utilities.AssemblyDirectory +
                                                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Quest.xml"));
                Logging.Write("Load TuanHA Hunter Defaut Quest Settings from a file complete");
                Logging.Write("----------------------------------");
                THHunterForm_Load(null, null);
            }
            else
            {
                Logging.Write("----------------------------------");
                Logging.Write("File not exists: " + Utilities.AssemblyDirectory +
                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut Quest.xml");
                Logging.Write("Load TuanHA Hunter Defaut AFK Quest from a file fail.");
                Logging.Write("----------------------------------");
            }
        }

        private void FullAFK_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                Classname.GetCurrentSpec() + " Hunter " +
                "Full AFK Mode: Work best with BGBuddy, ArcheologyBuddy, DungeonBuddy, Grind Bot, Questing...",
                "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Logging.Write("----------------------------------");
            Logging.Write("Full AFK Mode On");
            Logging.Write("----------------------------------");

            if (File.Exists(Utilities.AssemblyDirectory +
                            @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut AFK.xml"))
            {
                Logging.Write("----------------------------------");
                THSettings.Instance.LoadFromXML(XElement.Load(Utilities.AssemblyDirectory +
                                                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut AFK.xml"));
                Logging.Write("Load TuanHA Hunter Defaut AFK Settings from a file complete");
                Logging.Write("----------------------------------");
                THHunterForm_Load(null, null);
            }
            else
            {
                Logging.Write("----------------------------------");
                Logging.Write("File not exists: " + Utilities.AssemblyDirectory +
                              @"\Routines\TuanHAHunter\Preset\TuanHA Hunter Defaut AFK.xml");
                Logging.Write("Load TuanHA Hunter Defaut AFK Settings from a file fail.");
                Logging.Write("----------------------------------");
            }
        }

        private void SaveSetting_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Setting File|*.xml";
            saveFileDialog.Title = "Save Setting to a File";
            saveFileDialog.InitialDirectory = Utilities.AssemblyDirectory +
                                              @"\Routines\TuanHAHunter\User Settings\";
            saveFileDialog.DefaultExt = "xml";
            saveFileDialog.FileName = "TuanHA Hunter " + Classname.GetCurrentSpec();

            saveFileDialog.ShowDialog();

            //if (DialogResult != DialogResult.Abort &&
            //    DialogResult != DialogResult.Ignore &&
            //    DialogResult != DialogResult.No &&
            //    DialogResult != DialogResult.None &&
            //    DialogResult != DialogResult.Retry &&
            //    DialogResult != DialogResult.Cancel)
            //{
            //    Logging.Write(DialogResult.ToString());
            //    return;
            //}

            if (saveFileDialog.FileName.Contains(".xml"))
            {
                //Logging.Write(DialogResult.ToString());
                THSettings.Instance.SaveToFile(saveFileDialog.FileName);
                Logging.Write("----------------------------------");
                Logging.Write("Save Setting to: " + saveFileDialog.FileName);
                Logging.Write("----------------------------------");
            }
        }

        private void LoadSetting_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
                {
                    Filter = "Setting File|*.xml",
                    Title = "Load Setting from a File",
                    InitialDirectory = Utilities.AssemblyDirectory + @"\Routines\TuanHAHunter\User Settings\"
                };
            openFileDialog.ShowDialog();


            if (openFileDialog.FileName.Contains(".xml"))
            {
                //Logging.Write(DialogResult.ToString());
                THSettings.Instance.LoadFromXML(XElement.Load(openFileDialog.FileName));
                Logging.Write("----------------------------------");
                Logging.Write("Load Setting from: " + openFileDialog.FileName);
                Logging.Write("----------------------------------");
                THHunterForm_Load(null, null);
            }
        }

        private void AutoCallPet_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoCallPet = AutoCallPet.Checked;
        }

        private void AutoFace_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoFace = AutoFace.Checked;
        }

        private void AutoMove_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoMove = AutoMove.Checked;
        }

        private void AutoRacial_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoRacial = AutoRacial.Checked;
        }

        private void AutoTarget_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoTarget = AutoTarget.Checked;
        }

        private void AttackOOC_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AttackOOC = AttackOOC.Checked;
        }

        private void UnittoStartAoE_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.UnittoStartAoE = (int) UnittoStartAoE.Value;
        }

        private void UseFood_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.UseFood = UseFood.Checked;
        }

        private void UseFoodHP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.UseFoodHP = (int) UseFoodHP.Value;
        }

        private void PauseKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (PauseKey.SelectedIndex == i)
                {
                    THSettings.Instance.PauseKey = i;
                }
            }
        }

        private void StrafleLeft_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (StrafleLeft.SelectedIndex == i)
                {
                    THSettings.Instance.StrafleLeft = i;
                }
            }
        }

        private void Forward_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (Forward.SelectedIndex == i)
                {
                    THSettings.Instance.Forward = i;
                }
            }
        }

        private void StrafleRight_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (StrafleRight.SelectedIndex == i)
                {
                    THSettings.Instance.StrafleRight = i;
                }
            }
        }

        private void TurnLeft_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (TurnLeft.SelectedIndex == i)
                {
                    THSettings.Instance.TurnLeft = i;
                }
            }
        }

        private void Backward_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (Backward.SelectedIndex == i)
                {
                    THSettings.Instance.Backward = i;
                }
            }
        }

        private void TurnRight_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (TurnRight.SelectedIndex == i)
                {
                    THSettings.Instance.TurnRight = i;
                }
            }
        }

        private void ProfBuff_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 7; i++)
            {
                if (ProfBuff.SelectedIndex == i)
                {
                    THSettings.Instance.ProfBuff = i;
                }
            }
        }

        private void ProfBuffHP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ProfBuffHP = (int) ProfBuffHP.Value;
        }

        private void Trinket1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 7; i++)
            {
                if (Trinket1.SelectedIndex == i)
                {
                    THSettings.Instance.Trinket1 = i;
                }
            }
        }

        private void Trinket1HP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Trinket1HP = (int) Trinket1HP.Value;
        }

        private void Trinket2_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 7; i++)
            {
                if (Trinket2.SelectedIndex == i)
                {
                    THSettings.Instance.Trinket2 = i;
                }
            }
        }

        private void Trinket2HP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Trinket2HP = (int) Trinket2HP.Value;
        }

        private void BurstKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 46; i++)
            {
                if (BurstKey.SelectedIndex == i)
                {
                    THSettings.Instance.BurstKey = i;
                }
            }
        }

        private void BurstHP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.BurstHP = (int) BurstHP.Value;
        }

        private void AutoAoE_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoAoE = AutoAoE.Checked;
        }

        private void AutoAspect_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoAspect = AutoAspect.Checked;
        }

        private void IntimidationInterrupt_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IntimidationInterrupt = IntimidationInterrupt.Checked;
        }

        private void IntimidationInterruptMS_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IntimidationInterruptMS = (int) IntimidationInterruptMS.Value;
        }

        private void IntimidationLowHP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IntimidationLowHP = IntimidationLowHP.Checked;
        }

        private void IntimidationLowHPPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IntimidationLowHPPercent = (int) IntimidationLowHPPercent.Value;
        }

        private void ScatterShotInterrupt_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ScatterShotInterrupt = ScatterShotInterrupt.Checked;
        }

        private void ScatterShotInterruptMS_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ScatterShotInterruptMS = (int) ScatterShotInterruptMS.Value;
        }

        private void SilencingShotInterrupt_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SilencingShotInterrupt = SilencingShotInterrupt.Checked;
        }

        private void SilencingShotInterruptMS_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SilencingShotInterruptMS = (int) SilencingShotInterruptMS.Value;
        }

        private void SilencingShotLowHP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SilencingShotLowHP = SilencingShotLowHP.Checked;
        }

        private void SilencingShotLowHPPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SilencingShotLowHPPercent = (int) SilencingShotLowHPPercent.Value;
        }

        private void IntimidationFriendLowHP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IntimidationFriendLowHP = IntimidationFriendLowHP.Checked;
        }

        private void IntimidationFriendLowHPPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IntimidationFriendLowHPPercent = (int) IntimidationFriendLowHPPercent.Value;
        }

        private void ScatterShotFriendLowHP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ScatterShotFriendLowHP = ScatterShotFriendLowHP.Checked;
        }

        private void ScatterShotFriendLowHPPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ScatterShotFriendLowHPPercent = (int) ScatterShotFriendLowHPPercent.Value;
        }

        private void BestialWrathCD_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.BestialWrathCD = BestialWrathCD.Checked;
        }

        private void BestialWrathBurst_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.BestialWrathBurst = BestialWrathBurst.Checked;
        }

        private void BestialWrathLC_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.BestialWrathLC = BestialWrathLC.Checked;
        }

        private void RapidFireCD_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.RapidFireCD = RapidFireCD.Checked;
        }

        private void RapidFireBurst_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.RapidFireBurst = RapidFireBurst.Checked;
        }

        private void StampedeCD_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.StampedeCD = StampedeCD.Checked;
        }

        private void StampedeBurst_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.StampedeBurst = StampedeBurst.Checked;
        }

        private void Readiness_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Readiness = Readiness.Checked;
        }

        private void ReadinessBW_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessBW = ReadinessBW.Checked;
        }

        private void ReadinessRF_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessRF = ReadinessRF.Checked;
        }

        private void DeterrenceHP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.DeterrenceHP = DeterrenceHP.Checked;
        }

        private void DeterrenceHPPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.DeterrenceHPPercent = (int) DeterrenceHPPercent.Value;
        }

        private void DeterrenceUnit_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.DeterrenceUnit = DeterrenceUnit.Checked;
        }

        private void DeterrenceUnitNumber_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.DeterrenceUnitNumber = (int) DeterrenceUnitNumber.Value;
        }

        private void Misdirection_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Misdirection = Misdirection.Checked;
        }

        private void Disengage_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Disengage = Disengage.Checked;
        }

        private void DisengageUnitNumber_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.DisengageUnitNumber = (int) DisengageUnitNumber.Value;
        }

        private void MendPet_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.MendPet = MendPet.Checked;
        }

        private void MendPetPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.MendPetPercent = (int) MendPetPercent.Value;
        }

        private void PetTankAdd_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetTankAdd = PetTankAdd.Checked;
        }

        private void PetAttackHP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetAttackHP = (int) PetAttackHP.Value;
        }

        private void PetFollowHP_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetFollowHP = (int) PetFollowHP.Value;
        }

        private void PetAttack_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetAttack = PetAttack.Checked;
        }

        private void PetFollow_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetFollow = PetFollow.Checked;
        }

        private void CallPetNumber_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.CallPetNumber = (int) CallPetNumber.Value;
        }

        private void PetFollowDist_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetFollowDist = PetFollowDist.Checked;
        }

        private void PetFollowDistYard_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetFollowDistYard = (int) PetFollowDistYard.Value;
        }

        private void Cower_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Cower = Cower.Checked;
        }

        private void CowerPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.CowerPercent = (int) CowerPercent.Value;
        }

        private void ExhilarationPet_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ExhilarationPetHP = ExhilarationPet.Checked;
        }

        private void ExhilarationMePercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ExhilarationMe = (int) ExhilarationMePercent.Value;
        }

        private void ExhilarationPetPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ExhilarationPet = (int) ExhilarationPetPercent.Value;
        }

        private void ExhilarationMe_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Exhilaration = ExhilarationMe.Checked;
        }

        private void WidowVenom_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.WidowVenom = WidowVenom.Checked;
        }

        private void ConcussiveShot_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ConcussiveShot = ConcussiveShot.Checked;
        }

        private void TranquilizingShot_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.TranquilizingShot = TranquilizingShot.Checked;
        }

        private void KillShotOffTarget_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.KillShotOffTarget = KillShotOffTarget.Checked;
        }

        private void SpiritMend_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SpiritMend = SpiritMend.Checked;
        }

        private void SpiritMendMe_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SpiritMendMe = (int) SpiritMendMe.Value;
        }

        private void SpiritMendP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SpiritMendP = SpiritMendP.Checked;
        }

        private void SpiritMendPet_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SpiritMendPet = (int) SpiritMendPet.Value;
        }

        private void AttackASAP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AttackASAP = AttackASAP.Checked;
        }

        private void MarkASAP_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.MarkASAP = MarkASAP.Checked;
        }

        private void MasterCallMe_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.MasterCallMe = MasterCallMe.Checked;
        }

        private void LastStand_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.LastStand = LastStand.Checked;
        }

        private void LastStandPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.LastStandPercent = (int) LastStandPercent.Value;
        }

        private void PetGrowlPetAttackingMe_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetGrowlPetAttackingMe = PetGrowlPetAttackingMe.Checked;
        }

        private void RoarofSacrifice_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.RoarofSacrifice = RoarofSacrifice.Checked;
        }

        private void RoarofSacrificePercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.RoarofSacrificePercent = (int) RoarofSacrificePercent.Value;
        }

        private void RoarofSacrificeUnitMode_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.RoarofSacrificeUnitMode = RoarofSacrificeUnitMode.Checked;
        }

        private void RoarofSacrificeUnit_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.RoarofSacrificeUnit = (int) RoarofSacrificeUnit.Value;
        }

        private void BullHeaded_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.BullHeaded = BullHeaded.Checked;
        }

        private void Flare_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Flare = Flare.Checked;
        }

        private void FreezingTrap_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FreezingTrap = FreezingTrap.Checked;
        }

        private void AttackASAPInStealth_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AttackASAPInStealth = AttackASAPInStealth.Checked;
        }

        private void ScatterShotMoM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ScatterShotMoM = ScatterShotMoM.Checked;
        }

        private void ExplosiveTrapMoM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ExplosiveTrapMoM = ExplosiveTrapMoM.Checked;
        }

        private void ExplosiveTrapMoMDistance_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ExplosiveTrapMoMDistance = (int) ExplosiveTrapMoMDistance.Value;
        }

        private void SnakeTrapMoM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SnakeTrapMoM = SnakeTrapMoM.Checked;
        }

        private void SnakeTrapMoMDistance_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SnakeTrapMoMDistance = (int) SnakeTrapMoMDistance.Value;
        }

        private void FreezingTrapMoM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FreezingTrapMoM = FreezingTrapMoM.Checked;
        }

        private void FreezingTrapMoMDistance_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FreezingTrapMoMDistance = (int) FreezingTrapMoMDistance.Value;
        }

        private void IceTrapMoM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IceTrapMoM = IceTrapMoM.Checked;
        }

        private void IceTrapMoMDistance_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IceTrapMoMDistance = (int) IceTrapMoMDistance.Value;
        }

        private void ExplosiveTrapDPS_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ExplosiveTrapDPS = ExplosiveTrapDPS.Checked;
        }

        private void SerpentStingImproved_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SerpentStingImproved = SerpentStingImproved.Checked;
        }

        private void IceTrapSV_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.IceTrapSV = IceTrapSV.Checked;
        }

        private void ReadinessScS_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessScS = ReadinessScS.Checked;
        }

        private void ReadinessFT_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessFT = ReadinessFT.Checked;
        }

        private void ReadinessSiS_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessSiS = ReadinessSiS.Checked;
        }

        private void ReadinessDe_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessDe = ReadinessDe.Checked;
        }

        private void Camouflage_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.Camouflage = Camouflage.Checked;
        }

        private void SearchRange_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SearchRange = (int) SearchRange.Value;
        }

        private void SearchInterval_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SearchInterval = (int) SearchInterval.Value;
        }

        private void CallPetNumberMM_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.CallPetNumberMM = (int) CallPetNumberMM.Value;
        }

        private void CallPetNumberSV_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.CallPetNumberSV = (int) CallPetNumberSV.Value;
        }

        private void CamouflageCombat_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.CamouflageCombat = CamouflageCombat.Checked;
        }

        private void CamouflageCombatPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.CamouflageCombatPercent = (int) CamouflageCombatPercent.Value;
        }

        private void FeignDeath_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FeignDeath = FeignDeath.Checked;
        }

        private void FeignDeathPercent_ValueChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FeignDeathPercent = (int) FeignDeathPercent.Value;
        }

        private void SnakeTrapCasterHealer_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.SnakeTrapCasterHealer = SnakeTrapCasterHealer.Checked;
        }

        private void AutoSetFocus_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AutoSetFocus = AutoSetFocus.Checked;
        }

        private void FreezingTrapODM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FreezingTrapODM = FreezingTrapODM.Checked;
        }

        private void FreezingTrapODMDPS_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FreezingTrapODMDPS = FreezingTrapODMDPS.Checked;
        }

        private void FreezingTrapODMHealer_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.FreezingTrapODMHealer = FreezingTrapODMHealer.Checked;
        }

        private void FocusFreezingTrap_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (FocusFreezingTrap.SelectedIndex == i)
                {
                    THSettings.Instance.FocusFreezingTrap = i;
                }
            }
        }

        private void TargetFreezingTrap_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (TargetFreezingTrap.SelectedIndex == i)
                {
                    THSettings.Instance.TargetFreezingTrap = i;
                }
            }
        }

        private void InterruptAll_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.InterruptAll = InterruptAll.Checked;
        }

        private void InterruptTarget_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.InterruptTarget = InterruptTarget.Checked;
        }

        private void InterruptFocus_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.InterruptFocus = InterruptFocus.Checked;
        }

        private void ReadinessLR_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessLR = ReadinessLR.Checked;
        }

        private void ReadinessAM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.ReadinessAM = ReadinessAM.Checked;
        }

        private void ScareBeastKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (ScareBeastKey.SelectedIndex == i)
                {
                    THSettings.Instance.ScareBeastKey = i;
                }
            }
        }

        private void TrapSmokeBomb_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.TrapSmokeBomb = TrapSmokeBomb.Checked;
        }

        private void AMoCLRCD_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AMoCLRCD = AMoCLRCD.Checked;
        }

        private void AMoCLRCBurst_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.AMoCLRCBurst = AMoCLRCBurst.Checked;
        }

        private void PetStunMoM_CheckedChanged(object sender, EventArgs e)
        {
            THSettings.Instance.PetStunMoM = PetStunMoM.Checked;
        }
    }
}